<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function fn (num = 0) {
      if (num > 10) {
        return
      }
      num++;
      console.log(num)

      fn(num)
      console.log("取消副作用", num)
    }
    fn()
    //伪代码
    function test () {
      num = 1
      console.log(num)
      function test () {
        num = 2;
        console.log(num)
        function test () {
          num = 3
          console.log(num)
          // ...
          console.log("取消副作用", num)
        }
        console.log("取消副作用", num)
      }
      console.log("取消副作用", num)
    }
  </script>
</body>

</html>